package com.yuliang.controller;


import com.yuliang.domain.R;
import com.yuliang.domain.entity.Article;
import com.yuliang.service.ArticleService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/article")
@Api(description = "文章相关接口")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/hotArticleList")
    @ApiOperation(value = "热门文章列表",notes = "获取浏览量最高的前10篇文章")
    public R hotArticleList(){
        return articleService.hotArticleList();
    }


    @GetMapping("/articleList")
    @ApiOperation(value = "分页查询文章列表",notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页号"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小"),
            @ApiImplicitParam(name = "categoryId",value = "分类id")
    })
    public R articleList(int pageNum,int pageSize,Long categoryId){
        return articleService.articleList(pageNum,pageSize,categoryId);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "文章详情",notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "文章id")
    })
    public R getArticleDetail(@PathVariable("id") Long id){
        return articleService.getArticleDetail(id);
    }

    @PutMapping("/updateViewCount/{id}")
    @ApiOperation(value = "更新文章浏览量",notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "文章id")
    })
    public R updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }
}
